const api = require('../../utils/api.js')
import { $wuxToast } from '../../dist/index'
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getAllType()
  },
  getAllType(){
    wx.showLoading({
      title: '加载中',
    })
    var that = this
    wx.request({
      url: api.getAllType,
      success(res){
        that.setData({
          questionTypeList: res.data.data
        })
        that.getAllQuestionByType(res.data.data[0].id)
      }
    })
  },
  getAllQuestionByTypeBind(e){
    this.getAllQuestionByType(e.currentTarget.dataset.id)
  },
  getAllQuestionByType(id){
    var that = this
    wx.request({
      url: api.getAllUrgencyQuestionByType,
      data:{
        type: id
      },
      success(res){
        that.setData({
          questionList: res.data.data
        })
        if(res.data.data.length == 0){
          that.showToastErr("查询为空")
        }
        wx.hideLoading()
      }
    })
  },
  toDetail(e){
    wx.navigateTo({
      url: 'urgencyDetail/urgencyDetail?question='+ JSON.stringify(e.currentTarget.dataset.question)
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  showToastErr(info) {
    $wuxToast().show({
        type: 'forbidden',
        duration: 1500,
        color: '#fff',
        text: info,
        success: () => {}
    })
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})